﻿// Copyright (c) 2012 Mokah Nnamezie & Andrew Cooper
// Neo4Net graph database - http://neo4net.codeplex.com
//
// This file is part of Neo4Net - a .Net port of the Neo4j graph database
//
// Neo4Net is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

namespace Neo4Net.Kernel
{
    using Neo4Net.Compat;

    public class IdType : Enumeration<IdType>
    {
        public static readonly IdType Node = new IdType("Node", 35, true);
        public static readonly IdType Relationship = new IdType("Relationship", 35, true);
        public static readonly IdType Property = new IdType("Property", 36, true);
        public static readonly IdType StringBlock = new IdType("StringBlock", 36, true);
        public static readonly IdType ArrayBlock = new IdType("ArrayBlock", 36, true);
        public static readonly IdType PropertyIndex = new IdType("PropertyIndex", false);
        public static readonly IdType PropertyIndexBlock = new IdType("PropertyIndexBlock", false);
        public static readonly IdType RelationshipType = new IdType("RelationshipType", 16, false);
        public static readonly IdType RelationshipTypeBlock = new IdType("RelationshipTypeBlock", false);
        public static readonly IdType NeostoreBlock = new IdType("NeostoreBlock", false);

        private readonly long max;
        private readonly bool allowAggressiveReuse;

        private IdType(string name, bool allowAggressiveReuse)
            : this(name, 32, allowAggressiveReuse)
        {
        }

        private IdType(string name, int bits, bool allowAggressiveReuse)
            : base(name)
        {
            this.allowAggressiveReuse = allowAggressiveReuse;
            this.max = (1L << bits) - 1;
        }

        public long MaxValue
        {
            get { return this.max; }
        }

        public bool AllowAggressiveReuse
        {
            get { return allowAggressiveReuse; }
        }

        public int GrabSize
        {
            get { return allowAggressiveReuse ? 50000 : 1024; }
        }
    }
}
